package com.huya.controller.admin;

import com.huya.common.result.PageResult;
import com.huya.common.result.Result;
import com.huya.pojo.dto.TestDTO;
import com.huya.pojo.dto.TestPageQueryDTO;
import com.huya.pojo.entity.PsychologicalTest;
import com.huya.pojo.entity.TestQuestion;
import com.huya.service.PsychologicalTestService;
import com.huya.service.TestQuestionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/tests")
@Slf4j
public class PsychologicalTestController {

    @Autowired
    private PsychologicalTestService psychologicalTestService;

    @Autowired
    private TestQuestionService testQuestionService;

    /**
     * 分页查询心理测试列表
     * @param testPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> page(TestPageQueryDTO testPageQueryDTO) {
        log.info("psychologicalTest: {}", testPageQueryDTO);
        PageResult pageResult = psychologicalTestService.pageQuery(testPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据id查询心理测试详情
     * @param testId
     * @return
     */
    @GetMapping("/{testId}")
    public Result<PsychologicalTest> getById(@PathVariable Long testId) {
        log.info("psychologicalTest: {}", testId);
        PsychologicalTest psychologicalTest = psychologicalTestService.getTestById(testId);
        return Result.success(psychologicalTest);
    }

    /**
     *  根据id查询测试题目列表
     * @param testId
     * @return
     */
    @GetMapping("/question")
    public Result<List<TestQuestion>> getQuestionByTestId(Long testId) {
        log.info("psychologicalTest: {}", testId);
        List<TestQuestion> testQuestions = testQuestionService.getQuestionByTestId(testId);
        return Result.success(testQuestions);
    }

    /**
     * 新增心理测试
     * @param testDTO
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody TestDTO testDTO) {
        log.info("psychologicalTest: {}", testDTO);
        psychologicalTestService.add(testDTO);
        return Result.success();
    }
    @DeleteMapping
    public Result delete(Long testId) {
        log.info("psychologicalTest: {}", testId);
        psychologicalTestService.delete(testId);
        return Result.success();
    }
}
